package com.zyj.retry;

import com.zyj.retry.dto.Dog;
import com.zyj.retry.service.RetryService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.retry.annotation.EnableRetry;

@EnableRetry
@SpringBootApplication
public class App {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
        RetryService retryService = context.getBean(RetryService.class);
        //第一次执行, 遇到异常不会进行重试
        try {
            retryService.doWrongOnce();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        System.out.println("-------------------------");
        //第二次执行, 遇到异常会进行重试
        try {
            Dog dog = retryService.doWrong("recorver dog", 12);
            System.out.println("output dog = " + dog);
        } catch (Exception e) {
            System.out.println("catch");
            System.out.println(e.getMessage());
        }
    }
}
